package com.nari.ysphd.util;

import android.widget.Toast;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by jackeysun on 2019/7/17
 */

public class TextUtils {

    private static final Pattern pattern = Pattern.compile("[^a-zA-Z0-9\\u4E00-\\u9FA5_,.?!:;…~_\\-\"\"/@*+'()<>{}/[/]()<>{}\\[\\]=%&$|\\/♀♂#¥£¢€\"^` ，。？！：；……～" +
            "“”、“（）”、（——）‘’@‘·’＆＊＃《》￥《〈〉》〈＄〉［］￡［］｛｝｛｝￠【】【】％〖〗〖〗／〔〕〔〕＼『』『』＾「」「」｜﹁﹂｀．]");
    private static final Pattern pattern2 = Pattern.compile("[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？§№☆★○●◎◇◇◆□△▲■※＃→←↑-]");
    private static final Pattern pattern3 = Pattern.compile("[`~!@#$%^&*()+=|{}':;',\\[\\]<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？§№☆★○●◎◇◇◆□△▲■※＃→←↑-]");
    private static final Pattern pattern4 = Pattern.compile("[`~@#$%^&*()+=|{}':;'\\[\\]<>/~！@#￥%……&*（）——+|{}【】‘；：”“’、§№☆★○●◎◇◇◆□△▲■※＃→←↑-]");


    public static boolean isSpecialCharacter(String txt) {
        //表情
        Matcher matcher = pattern.matcher(txt);
        //特殊字符
        Matcher matcher4 = pattern4.matcher(txt);
        if (!matcher.find()) {
            if (matcher4.find()) {
                return true;
            }
            if (txt.equals(" ")) {
                return true;
            }
            return false;
        } else {
            return true;
        }
    }

    public static String desensitization(String name){
        StringBuilder desensitization = new StringBuilder();
        if(android.text.TextUtils.isEmpty(name)){
            return desensitization.append("").toString();
        }
        for (int i = 0; i < name.length(); i++){
            if (i == 0){
                desensitization.append(name.charAt(i));
            }else {
                desensitization.append("*");
            }
        }
        return desensitization.toString();
    }
}
